#***************************************************************#
#                                                               #
#                 Replication file (PART 2) for:                #
#                                                               #
#         "The Effect of Anger Appeals on the Support for       #
#                     Secessionist Parties"                     #
#                        Barceló, Joan                          #
#                  Journal of Politics (JOP)                    #
#               Last updated: 10 December 2022                  #
#                                                               #
#****************************************************************

#################
#               #
# Load packages #
#               #
#################

library(rstudioapi)
library(dplyr)

#############
# Load Data #
#############

current_path <- getActiveDocumentContext()$path 
setwd(dirname(current_path))

SurveyData_posneg <- readRDS('SurveyData_posneg.RDS')
SurveyData_anger <- readRDS('SurveyData_anger.RDS')
SurveyData_fear <- readRDS('SurveyData_fear.RDS')
SurveyData_pride <- readRDS('SurveyData_pride.RDS')
SurveyData_hope <- readRDS('SurveyData_hope.RDS')
SurveyData_sadness <- readRDS('SurveyData_sadness.RDS')
SurveyData_happy <- readRDS('SurveyData_happy.RDS')
SurveyData_disgust <- readRDS('SurveyData_disgust.RDS')

#############
# Table 2   #
#############

####Positive vs. Negative emotions:

#Anger/Violence treatment:
round(prop.table(table(SurveyData_posneg[complete.cases(SurveyData_posneg$treat_vio_posneg),]$treat_vio_posneg)),3)
#National pride treatment:
round(prop.table(table(SurveyData_posneg[complete.cases(SurveyData_posneg$treat_demo_posneg),]$treat_demo_posneg)),3)
#Referendum vote treatment:
round(prop.table(table(SurveyData_posneg[complete.cases(SurveyData_posneg$treat_vote_posneg),]$treat_vote_posneg)),3)
#Emotionally neutral treatment
round(prop.table(table(SurveyData_posneg[complete.cases(SurveyData_posneg$placebo_posneg),]$placebo_posneg)),3)

#Anger results:
anger_means <- aggregate(as.numeric(SurveyData_anger[complete.cases(SurveyData_anger$anger),]$anger), list(SurveyData_anger[complete.cases(SurveyData_anger$anger),]$treatment), FUN=mean)
round(anger_means$x, 2) 

#Fear results:
fear_means <- aggregate(as.numeric(SurveyData_fear[complete.cases(SurveyData_fear$fear),]$fear), list(SurveyData_fear[complete.cases(SurveyData_fear$fear),]$treatment), FUN=mean)
round(fear_means$x, 2) 

#Sadness results:
sadness_means <- aggregate(as.numeric(SurveyData_sadness[complete.cases(SurveyData_sadness$sadness),]$sadness), list(SurveyData_sadness[complete.cases(SurveyData_sadness$sadness),]$treatment), FUN=mean)
round(sadness_means$x, 2) 

#Disgust results:
disgust_means <- aggregate(as.numeric(SurveyData_disgust[complete.cases(SurveyData_disgust$disgust),]$disgust), list(SurveyData_disgust[complete.cases(SurveyData_disgust$disgust),]$treatment), FUN=mean)
round(disgust_means$x, 2) 

#Pride results:
pride_means <- aggregate(as.numeric(SurveyData_pride[complete.cases(SurveyData_pride$pride),]$pride), list(SurveyData_pride[complete.cases(SurveyData_pride$pride),]$treatment), FUN=mean)
round(pride_means$x, 2) 

#Hope results:
hope_means <- aggregate(as.numeric(SurveyData_hope[complete.cases(SurveyData_hope$hope),]$hope), list(SurveyData_hope[complete.cases(SurveyData_hope$hope),]$treatment), FUN=mean)
round(hope_means$x, 2) 

#Happiness results:
happiness_means <- aggregate(as.numeric(SurveyData_happy[complete.cases(SurveyData_happy$happy),]$happy), list(SurveyData_happy[complete.cases(SurveyData_happy$happy),]$treatment), FUN=mean)
round(happiness_means$x, 2)


#######################
# In-text information #
#######################

#T-test comparisons of anger vs. every other discrete emotion in the treatment condition:

#anger vs. disgust
t.test(as.numeric(SurveyData_anger[complete.cases(SurveyData_anger$anger) & SurveyData_anger$treatment == "Violence treatment",]$anger),
       as.numeric(SurveyData_disgust[complete.cases(SurveyData_disgust$disgust) & SurveyData_disgust$treatment == "Violence treatment",]$disgust))

#anger vs. sadness
t.test(as.numeric(SurveyData_anger[complete.cases(SurveyData_anger$anger) & SurveyData_anger$treatment == "Violence treatment",]$anger),
       as.numeric(SurveyData_sadness[complete.cases(SurveyData_sadness$sadness) & SurveyData_sadness$treatment == "Violence treatment",]$sadness))

#anger vs. fear
t.test(as.numeric(SurveyData_anger[complete.cases(SurveyData_anger$anger) & SurveyData_anger$treatment == "Violence treatment",]$anger),
       as.numeric(SurveyData_fear[complete.cases(SurveyData_fear$fear) & SurveyData_fear$treatment == "Violence treatment",]$fear))

#anger vs. pride
t.test(as.numeric(SurveyData_anger[complete.cases(SurveyData_anger$anger) & SurveyData_anger$treatment == "Violence treatment",]$anger),
       as.numeric(SurveyData_pride[complete.cases(SurveyData_pride$pride) & SurveyData_pride$treatment == "Violence treatment",]$pride))

#anger vs. hope
t.test(as.numeric(SurveyData_anger[complete.cases(SurveyData_anger$anger) & SurveyData_anger$treatment == "Violence treatment",]$anger),
       as.numeric(SurveyData_hope[complete.cases(SurveyData_hope$hope) & SurveyData_hope$treatment == "Violence treatment",]$hope))

#anger vs. happiness
t.test(as.numeric(SurveyData_anger[complete.cases(SurveyData_anger$anger) & SurveyData_anger$treatment == "Violence treatment",]$anger),
       as.numeric(SurveyData_happy[complete.cases(SurveyData_happy$happy) & SurveyData_disgust$treatment == "Violence treatment",]$happy))

#% of respondents who correctly identified the event in the Anger/Violence treatment leaflet: 69.4%
prop.table(table(SurveyData_posneg$treat_vio_date))

#% of respondents who correctly identified the police body portrayed in the Anger/Violence treatment leaflet: 79.7%
prop.table(table(SurveyData_posneg$treat_vio_policebody))

#############################
# Online Appendix M and M.2 #
#############################

prop.table(table(SurveyData_posneg$gender))*100
prop.table(table(SurveyData_posneg$age))*100
prop.table(table(SurveyData_posneg$education))*100
prop.table(table(SurveyData_posneg$province))*100

#Anger results:
SurveyData_anger <- SurveyData_anger[complete.cases(SurveyData_anger$anger),]
anger_means <- aggregate(as.numeric(SurveyData_anger[as.numeric(SurveyData_anger$pop_size) <= 4,]$anger), list(SurveyData_anger[as.numeric(SurveyData_anger$pop_size) <= 4,]$treatment), FUN=mean)
round(anger_means$x, 2) 

#Fear results:
SurveyData_fear <- SurveyData_fear[complete.cases(SurveyData_fear$fear),]
fear_means <- aggregate(as.numeric(SurveyData_fear[as.numeric(SurveyData_fear$pop_size) <= 4,]$fear), list(SurveyData_fear[as.numeric(SurveyData_fear$pop_size) <= 4,]$treatment), FUN=mean)
round(fear_means$x, 2) 

#Sadness results:
SurveyData_sadness <- SurveyData_sadness[complete.cases(SurveyData_sadness$sadness),]
sadness_means <- aggregate(as.numeric(SurveyData_sadness[as.numeric(SurveyData_sadness$pop_size) <= 4,]$sadness), list(SurveyData_sadness[as.numeric(SurveyData_sadness$pop_size) <= 4,]$treatment), FUN=mean)
round(sadness_means$x, 2) 

#Disgust results:
SurveyData_disgust <- SurveyData_disgust[complete.cases(SurveyData_disgust$disgust),]
disgust_means <- aggregate(as.numeric(SurveyData_disgust[as.numeric(SurveyData_disgust$pop_size) <= 4,]$disgust), list(SurveyData_disgust[as.numeric(SurveyData_disgust$pop_size) <= 4,]$treatment), FUN=mean)
round(disgust_means$x, 2) 

#Pride results:
SurveyData_pride <- SurveyData_pride[complete.cases(SurveyData_pride$pride),]
pride_means <- aggregate(as.numeric(SurveyData_pride[as.numeric(SurveyData_pride$pop_size) <= 4,]$pride), list(SurveyData_pride[as.numeric(SurveyData_pride$pop_size) <= 4,]$treatment), FUN=mean)
round(pride_means$x, 2) 

#Hope results:
SurveyData_hope <- SurveyData_hope[complete.cases(SurveyData_hope$hope),]
hope_means <- aggregate(as.numeric(SurveyData_hope[as.numeric(SurveyData_hope$pop_size) <= 4,]$hope), list(SurveyData_hope[as.numeric(SurveyData_hope$pop_size) <= 4,]$treatment), FUN=mean)
round(hope_means$x, 2) 

#Happiness results:
SurveyData_happy <- SurveyData_happy[complete.cases(SurveyData_happy$happy),]
happy_means <- aggregate(as.numeric(SurveyData_happy[as.numeric(SurveyData_happy$pop_size) <= 4,]$happy), list(SurveyData_happy[as.numeric(SurveyData_happy$pop_size) <= 4,]$treatment), FUN=mean)
round(happy_means$x, 2)


